Colin Murphy
11/4/2021
plotly and data.table librariesmtcars datasetUse the plotly package to make some cool graphics!
avg.repub <- apply(votes.repub, MARGIN = 1, function(x) mean(x, na.rm = T)) %>%
as.data.table(keep.rownames = T)
avg.repub[, states := state.abb]
plot_ly(avg.repub, z = ~., type = 'choropleth', color = ~., locations = ~states, locationmode = 'USA-states', colors = 'Reds') %>%
layout(title = 'Average Republican Vote Percentage by State (1856 - 1976)', geo = list(scope = 'usa', projection = list(type = 'albers usa')))